package lxs.swift.instance.action;


import lxs.swift.instance.StructInstance;
import lxs.swift.tool.Dater;

import java.util.Date;
import java.util.function.Function;


public class DateAction<Key> extends Action<Key, Date> {
    public DateAction(StructInstance<Key> instance, Function<Object, Date> convertor) {
        super(instance, convertor);
    }

    public void acc(Key key, long num) {
        Date value = getOr(key, new Date(0L));
        value.setTime(value.getTime() + num);
        set(key, value);
    }

    public String format(Date value) {
        if (value == null) {
            return "";
        }
        return Dater.of(value).formatDate();
    }
}
